import java.rmi.*;
import ResInterface.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.*;
import java.io.*;

public class testClient
{
    static String message = "blank";
    private static LinkedList<ResourceManager> rms = new LinkedList<ResourceManager>();
    private static LinkedList<ArrayList> transactions = new LinkedList<ArrayList>();
	private static String[] locations = {"a", "b", "c", "d"};
	
	// seed for generating random price of car and flight
	private final static int PRICE = 400;
	// number of unique flights
	private final static int UNIQUE_FLIGHTS_CARS = 4;
	// number of seats to add on a flight
	private final static int NUM_SEATS = 10;
    // default number of clients threads to run
    private final static int CLIENTS = 20;
    // default number of operations in a transaction
    private final static int OPS = 3;
	
    private static int clientOps = OPS;
    private static int clientThreads = CLIENTS;

	// file handlers
	private static File file = new File("out.txt");
	private static FileOutputStream fos;
	private static DataOutputStream dos;

    public static void main(String args[]) 
	throws RemoteException {

	try {

	      fos = 	new FileOutputStream(file);
	      dos =	new DataOutputStream(fos);

	  } catch (IOException e) {
	      e.printStackTrace();

	  }

	    testClient obj = new testClient();

	    String server = "localhost";
	    if (args.length == 1) {
			server = args[0]; 
		} else if(args.length == 2) {
			server = args[0];
			clientThreads = Integer.valueOf(args[1]).intValue();
		}
		else if(args.length == 3) {
			server = args[0];
			clientThreads = Integer.valueOf(args[1]).intValue();
			clientOps = Integer.valueOf(args[2]).intValue();
		}
	    else 
		{
			System.out.println ("Usage: java testClient [rmihost] [(opt)number of clients] [(opt)transactions per client]"); 
			System.exit(1); 
		}
		
	    try 
		{
			// get a reference to the rmiregistry
			Registry registry = LocateRegistry.getRegistry(server, 3501);
			for(int i = 0; i < clientThreads; i++) {
			    // get the proxy and the remote reference by rmiregistry lookup for each client thread
			    rms.add(i, (ResourceManager) registry.lookup("rebdavMiddleware"));
			    if(rms.get(i) != null)
				{
				    System.out.println("Successful");
				    System.out.println("Connected to RM #" + i);
				}
			    else
				{
				    System.out.println("Unsuccessful connection to RM #" + i);
				}
			    // make call on remote method
			}
		} 
	    catch (Exception e) 
		{	
		    System.err.println("testClient exception: " + e.toString());
		    e.printStackTrace();
		}

		// calculate the average response time for only one RM; three updates.		
		//averageTimeSingleRM();

		// calculate average response time for three RMs.
		averageTimeAllRMs();

		try {
			fos.close();
		} catch(IOException e) { }
		
		// Generate threads with random requests

		Random rand = new Random();
		int min = 2;
		int max = 22;
		ArrayList<Integer> random_trans;

		// generate the transactions for each client thread to execute
		for(int i = 0; i < clientThreads; i++) {
			random_trans = new ArrayList();
			for(int j = 0; j < clientOps; j++) {
				random_trans.add(j, rand.nextInt(max - min + 1) + min);
				System.out.println("Adding operation " + random_trans.get(j) + " to transaction " + i);
			}
			transactions.add(i, random_trans);
		}

		final int[] index = new int[1];
		
		for(int m = 0; m < clientThreads; m++) {
					
		}



		
	}
	 	
	// Time the average response time to go run three updates on a single resource manager
	public static void averageTimeSingleRM() {
		final int ROUNDS = 100;

		long average = 0;
		long total = 0;
		long startTime, endTime, totalTime;
		totalTime = 0;
		ResourceManager myRM = rms.get(0);
		try {
			for(int o = 0; o < ROUNDS; o++) {
				int xid = myRM.start();
				int cid = myRM.newCustomer(xid);			
			
				startTime = System.currentTimeMillis();
		
				for(int n = 0; n < 3; n++) {
					doOperation(myRM, 2, xid, cid);
				}
		
				endTime   = System.currentTimeMillis();
		
				myRM.commit(xid);

				totalTime = endTime - startTime;	
				try {
					dos.writeChars(totalTime + ", single, " + o + "\n");
				} catch(IOException e) {
				}
				
				total += totalTime;
				totalTime = 0; // reset !
				Thread.sleep(15);
			}
		} catch(Exception e) {
		}
		
		// output it println(average + ", avg single RM");
	}

	public static void averageTimeAllRMs() {
		final int ROUNDS = 100;
		long average = 0;
		long total = 0;
		long startTime, endTime, totalTime;
		totalTime = 0;
		ResourceManager myRM = rms.get(0);
		try {
			for(int o = 0; o < ROUNDS; o++) {
				int xid = myRM.start();
				int cid = myRM.newCustomer(xid);			
			
				startTime = System.currentTimeMillis();
		
				doOperation(myRM, 4, xid, cid); // add a room
				doOperation(myRM, 2, xid, cid); // add a flight
				doOperation(myRM, 3, xid, cid); // add a car
		
				endTime   = System.currentTimeMillis();
		
				myRM.commit(xid);
				
				totalTime = endTime - startTime;	
				try {
					dos.writeChars(totalTime + ", all, " + o + "\n");
				} catch(IOException e) {
				}
				
				total += totalTime;
				totalTime = 0; // reset !
				Thread.sleep(20);
			}

		} catch(Exception e) {
			System.out.println("here");
			e.printStackTrace();
		}

	}

	public static void doOperation(ResourceManager myRM, int op, int xid, int cid) {
	Random rand = new Random();
	int min = 0;
	int max = locations.length - 1;


	int Id, Cid;
    int flightNum;
    int flightPrice;
    int flightSeats;
    boolean Room;
    boolean Car;
    int price;
    int numRooms;
    int numCars;
    String location;

	
	Vector arguments = new Vector();
	arguments.add("dummyZero"); // always start with index 1
	arguments.add(xid);

	// get the command and do it
		switch(op) {
		case 1: // original help section - ignore
		    break;
		case 2:  //new flight
		    arguments.add(rand.nextInt(UNIQUE_FLIGHTS_CARS - min + 1) + min);
			arguments.add(rand.nextInt(NUM_SEATS - min + 1) + 1);
			arguments.add(PRICE);

		    System.out.println("Adding a new Flight using id: "+arguments.elementAt(1));
		    System.out.println("Flight number: "+arguments.elementAt(2));
		    System.out.println("Add Flight Seats: "+arguments.elementAt(3));
		    System.out.println("Set Flight Price: "+arguments.elementAt(4));
		    
		    try{
				Id = ((Integer) arguments.elementAt(1)).intValue();
				flightNum = ((Integer)arguments.elementAt(2)).intValue();
				flightSeats = ((Integer)arguments.elementAt(3)).intValue();
				flightPrice = ((Integer)arguments.elementAt(4)).intValue();
				if(myRM.addFlight(Id,flightNum,flightSeats,flightPrice))
				    System.out.println("Flight added");
				else
				    System.out.println("Flight could not be added");
			    }

		    catch(Exception e){
				System.out.println("EXCEPTION:");
				System.out.println(e.getMessage());
				e.printStackTrace();
		    }

		    break;
		    
		case 3:  //new Car
		   arguments.add(locations[rand.nextInt(max - min + 1) + min]);
		   arguments.add(rand.nextInt(NUM_SEATS - min + 1) + 1);
	           arguments.add(PRICE);
		   System.out.println(arguments.size());

		    System.out.println("Adding a new Car using id: "+arguments.elementAt(1));
		    System.out.println("Car Location: "+arguments.elementAt(2));
		    System.out.println("Add Number of Cars: "+arguments.elementAt(3));
		    System.out.println("Set Price: "+arguments.elementAt(4));
		    
		    try{
				Id = ((Integer) arguments.elementAt(1)).intValue();
				location = arguments.elementAt(2).toString();
				numCars = ((Integer)arguments.elementAt(3)).intValue();
				price = ((Integer)arguments.elementAt(4)).intValue();
				if(myRM.addCars(Id,location,numCars,price))
				    System.out.println("Cars added");
				else
				    System.out.println("Cars could not be added");
			    }
		    catch(Exception e){
				System.out.println("EXCEPTION:");
				System.out.println(e.getMessage());
				e.printStackTrace();
		    }
		    break;
		    
		case 4:  //new Room
			arguments.add(locations[rand.nextInt(max - min + 1) + min]);
		    arguments.add(rand.nextInt(UNIQUE_FLIGHTS_CARS - min + 1) + min);
			arguments.add(10);


		    System.out.println("Adding a new Room using id: "+arguments.elementAt(1));
		    System.out.println("Room Location: "+arguments.elementAt(2));
		    System.out.println("Add Number of Rooms: "+arguments.elementAt(3));
		    System.out.println("Set Price: "+arguments.elementAt(4));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			location = arguments.elementAt(2).toString();
			numRooms = ((Integer)arguments.elementAt(3)).intValue();
			price = ((Integer)arguments.elementAt(4)).intValue();
			if(myRM.addRooms(Id,location,numRooms,price))
			    System.out.println("Rooms added");
			else
			    System.out.println("Rooms could not be added");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 5:  //new Customer

		    System.out.println("Adding a new Customer using id:"+arguments.elementAt(1));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			int customer=myRM.newCustomer(Id);
			System.out.println("new customer id:"+customer);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 6: //delete Flight
		    arguments.add(rand.nextInt(UNIQUE_FLIGHTS_CARS - min + 1) + min);

		    System.out.println("Deleting a flight using id: "+arguments.elementAt(1));
		    System.out.println("Flight Number: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			flightNum = ((Integer)arguments.elementAt(2)).intValue();
			if(myRM.deleteFlight(Id,flightNum))
			    System.out.println("Flight Deleted");
			else
			    System.out.println("Flight could not be deleted");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 7: //delete Car
			arguments.add(locations[rand.nextInt(max - min + 1) + min]);

		    System.out.println("Deleting the cars from a particular location  using id: "+arguments.elementAt(1));
		    System.out.println("Car Location: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			location = arguments.elementAt(2).toString();
			
			if(myRM.deleteCars(Id,location))
			    System.out.println("Cars Deleted");
			else
			    System.out.println("Cars could not be deleted");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 8: //delete Room
  			arguments.add(locations[rand.nextInt(max - min + 1) + min]);
		 

		    System.out.println("Deleting all rooms from a particular location  using id: "+arguments.elementAt(1));
		    System.out.println("Room Location: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			location = arguments.elementAt(2).toString();
			if(myRM.deleteRooms(Id,location))
			    System.out.println("Rooms Deleted");
			else
			    System.out.println("Rooms could not be deleted");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 9: //delete Customer
		   	arguments.add(cid);

		    System.out.println("Deleting a customer from the database using id: "+arguments.elementAt(1));
		    System.out.println("Customer id: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			int customer = ((Integer)arguments.elementAt(2)).intValue();
			if(myRM.deleteCustomer(Id,customer))
			    System.out.println("Customer Deleted");
			else
			    System.out.println("Customer could not be deleted");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 10: //querying a flight
		    arguments.add(rand.nextInt(UNIQUE_FLIGHTS_CARS - min + 1) + min);

		    System.out.println("Querying a flight using id: "+arguments.elementAt(1));
		    System.out.println("Flight number: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			flightNum = ((Integer)arguments.elementAt(2)).intValue();
			int seats=myRM.queryFlight(Id,flightNum);
			System.out.println("Number of seats available:"+seats);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 11: //querying a Car Location
			arguments.add(locations[rand.nextInt(max - min + 1) + min]);
		
		    System.out.println("Querying a car location using id: "+arguments.elementAt(1));
		    System.out.println("Car location: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			location = arguments.elementAt(2).toString();
			numCars=myRM.queryCars(Id,location);
			System.out.println("number of Cars at this location:"+numCars);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 12: //querying a Room location
			arguments.add(locations[rand.nextInt(max - min + 1) + min]);

		    System.out.println("Querying a room location using id: "+arguments.elementAt(1));
		    System.out.println("Room location: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			location = arguments.elementAt(2).toString();
			numRooms=myRM.queryRooms(Id,location);
			System.out.println("number of Rooms at this location:"+numRooms);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 13: //querying Customer Information
			arguments.add(cid);
		    System.out.println("Querying Customer information using id: "+arguments.elementAt(1));
		    System.out.println("Customer id: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			int customer = ((Integer)arguments.elementAt(2)).intValue();
			String bill=myRM.queryCustomerInfo(Id,customer);
			if(bill.equals("")) {
				System.out.println("Customer did not exist.");
			} else {
				System.out.println("Customer info:"+bill);
			}
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;		       
		    
		case 14: //querying a flight Price
		    arguments.add(rand.nextInt(UNIQUE_FLIGHTS_CARS - min + 1) + min);

		    System.out.println("Querying a flight Price using id: "+arguments.elementAt(1));
		    System.out.println("Flight number: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			flightNum = ((Integer)arguments.elementAt(2)).intValue();
			price=myRM.queryFlightPrice(Id,flightNum);
			System.out.println("Price of a seat:"+price);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 15: //querying a Car Price
			arguments.add(locations[rand.nextInt(max - min + 1) + min]);
		    
		    System.out.println("Querying a car price using id: "+arguments.elementAt(1));
		    System.out.println("Car location: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			location = arguments.elementAt(2).toString();
			price=myRM.queryCarsPrice(Id,location);
			System.out.println("Price of a car at this location:"+price);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }			    
		    break;

		case 16: //querying a Room price
		   	arguments.add(locations[rand.nextInt(max - min + 1) + min]);
		    
		    System.out.println("Querying a room price using id: "+arguments.elementAt(1));
		    System.out.println("Room Location: "+arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			location = arguments.elementAt(2).toString();
			price=myRM.queryRoomsPrice(Id,location);
			System.out.println("Price of Rooms at this location:"+price);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 17:  //reserve a flight
		
		    arguments.add(rand.nextInt(UNIQUE_FLIGHTS_CARS - min + 1) + min);
			arguments.add(cid);


		    System.out.println("Reserving a seat on a flight using id: "+arguments.elementAt(1));
		    System.out.println("Customer id: "+arguments.elementAt(2));
		    System.out.println("Flight number: "+arguments.elementAt(3));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			int customer = ((Integer)arguments.elementAt(2)).intValue();
			flightNum = ((Integer)arguments.elementAt(3)).intValue();
			if(myRM.reserveFlight(Id,customer,flightNum))
			    System.out.println("Flight Reserved");
			else
			    System.out.println("Flight could not be reserved.");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 18:  //reserve a car
			arguments.add(cid);
		   	arguments.add(locations[rand.nextInt(max - min + 1) + min]);
		    
		    System.out.println("Reserving a car at a location using id: "+arguments.elementAt(1));
		    System.out.println("Customer id: "+arguments.elementAt(2));
		    System.out.println("Location: "+arguments.elementAt(3));
		    
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			int customer = ((Integer)arguments.elementAt(2)).intValue();
			location = arguments.elementAt(3).toString();
			
			if(myRM.reserveCar(Id,customer,location))
			    System.out.println("Car Reserved");
			else
			    System.out.println("Car could not be reserved.");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 19:  //reserve a room
			arguments.add(locations[rand.nextInt(max - min + 1) + min]);
			arguments.add(cid);
		    

		    System.out.println("Reserving a room at a location using id: "+arguments.elementAt(1));
		    System.out.println("Customer id: "+arguments.elementAt(2));
		    System.out.println("Location: "+arguments.elementAt(3));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			int customer = ((Integer)arguments.elementAt(2)).intValue();
			location = arguments.elementAt(3).toString();			
			if(myRM.reserveRoom(Id,customer,location))
			    System.out.println("Room Reserved");
			else
			    System.out.println("Room could not be reserved.");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		case 20:  //reserve an Itinerary
			arguments.add(cid);
			arguments.add(rand.nextInt(UNIQUE_FLIGHTS_CARS - min + 1) + min);
		    arguments.add(locations[rand.nextInt(max - min + 1) + min]);
			arguments.add("true");
			arguments.add("true");
		    

		    System.out.println("Reserving an Itinerary using id:"+arguments.elementAt(1));
		    System.out.println("Customer id:"+arguments.elementAt(2));
			System.out.println("Flight number"+arguments.elementAt(3));
		    System.out.println("Location for Car/Room booking:"+arguments.elementAt(arguments.size()-3));
		    System.out.println("Car to book?:"+arguments.elementAt(arguments.size()-2));
		    System.out.println("Room to book?:"+arguments.elementAt(arguments.size()-1));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			int customer = ((Integer)arguments.elementAt(2)).intValue();
			Car = true;
			location = arguments.elementAt(4).toString();
			Room = true;
			Vector flight_v = new Vector();
			flight_v.add((Integer) arguments.elementAt(3));
			if(myRM.itinerary(Id,customer, flight_v,location,Car,Room))
			    System.out.println("Itinerary Reserved");
			else
			    System.out.println("Itinerary could not be reserved.");
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    		    
		case 21:  //quit the testClient
		   
		    System.out.println("Terminating that testClient.");
	
		case 22:  //new Customer given id
		    arguments.add(cid);

		    System.out.println("Adding a new Customer using id:"+arguments.elementAt(1) + " and cid " +arguments.elementAt(2));
		    try{
			Id = ((Integer) arguments.elementAt(1)).intValue();
			Cid = ((Integer)arguments.elementAt(2)).intValue();
			boolean customer=myRM.newCustomer(Id,Cid);
			System.out.println("new customer id:"+Cid);
		    }
		    catch(Exception e){
			System.out.println("EXCEPTION:");
			System.out.println(e.getMessage());
			e.printStackTrace();
		    }
		    break;
		    
		default:
		    System.out.println("The interface does not support this command.");
		    break;
		}//end of switch	
		System.out.println("Exiting switch.");
	}   
    public Vector parse(String command)
    {
		Vector arguments = new Vector();
		StringTokenizer tokenizer = new StringTokenizer(command,",");
		String argument ="";
		while (tokenizer.hasMoreTokens())
		    {
			argument = tokenizer.nextToken();
			argument = argument.trim();
			arguments.add(argument);
		    }
		return arguments;
    }

    public int findChoice(String argument)
    {
		if (argument.compareToIgnoreCase("help")==0)
		    return 1;
		else if(argument.compareToIgnoreCase("newflight")==0)
		    return 2;
		else if(argument.compareToIgnoreCase("newcar")==0)
		    return 3;
		else if(argument.compareToIgnoreCase("newroom")==0)
		    return 4;
		else if(argument.compareToIgnoreCase("newcustomer")==0)
		    return 5;
		else if(argument.compareToIgnoreCase("deleteflight")==0)
		    return 6;
		else if(argument.compareToIgnoreCase("deletecar")==0)
		    return 7;
		else if(argument.compareToIgnoreCase("deleteroom")==0)
		    return 8;
		else if(argument.compareToIgnoreCase("deletecustomer")==0)
		    return 9;
		else if(argument.compareToIgnoreCase("queryflight")==0)
		    return 10;
		else if(argument.compareToIgnoreCase("querycar")==0)
		    return 11;
		else if(argument.compareToIgnoreCase("queryroom")==0)
		    return 12;
		else if(argument.compareToIgnoreCase("querycustomer")==0)
		    return 13;
		else if(argument.compareToIgnoreCase("queryflightprice")==0)
		    return 14;
		else if(argument.compareToIgnoreCase("querycarprice")==0)
		    return 15;
		else if(argument.compareToIgnoreCase("queryroomprice")==0)
		    return 16;
		else if(argument.compareToIgnoreCase("reserveflight")==0)
		    return 17;
		else if(argument.compareToIgnoreCase("reservecar")==0)
		    return 18;
		else if(argument.compareToIgnoreCase("reserveroom")==0)
		    return 19;
		else if(argument.compareToIgnoreCase("itinerary")==0)
		    return 20;
		else if (argument.compareToIgnoreCase("quit")==0)
		    return 21;
		else if (argument.compareToIgnoreCase("newcustomerid")==0)
		    return 22;
		else
		    return 666;

    }




    
    public void wrongNumber() {
		System.out.println("The number of arguments provided in this command are wrong.");
		System.out.println("Type help, <commandname> to check usage of this command.");
    }



    public int getInt(Object temp) throws Exception {
		try {
			return (new Integer((String)temp)).intValue();
		    }
		catch(Exception e) {
			throw e;
		    }
    }
    
    public boolean getBoolean(Object temp) throws Exception {
    	try {
    		return (new Boolean((String)temp)).booleanValue();
    	    }
    	catch(Exception e) {
    		throw e;
    	    }
    }

    public String getString(Object temp) throws Exception {
	try {	
		return (String)temp;
	    }
	catch (Exception e) {
		throw e;
	    }
    }
}
